package docmanager.operation.documentos;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import docmanager.business.objects.Documento;
import docmanager.business.objects.Sector;
import docmanager.business.objects.TipoDocumento;
import docmanager.db.ConnectionPool;

import bf.operation.Operation;
import bf.operation.OperationException;

public class OpModificarDocumento1 extends Operation {

	@Override
	public Map execute(HttpServletRequest request) throws OperationException {
		Map m = new HashMap();
		int id = Integer.parseInt((String)request.getParameter("id"));
		int idSector = Integer.parseInt((String)request.getParameter("idSector"));
		m.put("idSector", new Integer(idSector));
		try {
			Connection conn = ConnectionPool.getConnection();
			Documento doc = new Documento(conn, id);
			// Cargar los sectores del documento.
			doc.cargarSectores();
			
			List<Sector> sectores = Sector.obtenerTodosLosSectores(conn);
			List<TipoDocumento> tiposDocumento = TipoDocumento.obtenerTodosTipos(conn);
			m.put("documento", doc);
			m.put("sectores", sectores);
			m.put("tiposDoc", tiposDocumento);
			ConnectionPool.closeConn(conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new OperationException();
		}
		
		
		return m;
	}

	@Override
	public String getReturnURL() {
		// TODO Auto-generated method stub
		return "Documentos/ModificarDocumento.jsp";
	}

}
